package emergence.game.level.tiles;

import java.util.ArrayList;
import java.util.Collection;

import emergence.game.Tickable;
import emergence.game.gfx.ColoredSprite;
import emergence.game.gfx.Renderable;

public abstract class Tile implements Renderable, Comparable<Tile> {
	
	private static final Collection<Tile> tiles = new ArrayList<>();
	
	protected String name;
	protected boolean solid;
	protected boolean emitter;
	
	protected ColoredSprite sprite;
	
	public Tile(String name, boolean isSolid) {
		this.name = name;
		this.solid = isSolid;
	}
	
	
	public Tile(String name, ColoredSprite sprite, boolean isSolid) {
		this.name = name;
		this.solid = isSolid;
		this.sprite = sprite;
		
		Tile.addTile(this);
	}
	
	
	public String name() {
		return name;
	}
	
	
	public boolean isSolid() {
		return solid;
	}
	
	
	public boolean isEmitter() {
		return emitter;
	}
	
	
	public ColoredSprite sprite() {
		return sprite;
	}
	
	
	public ColoredSprite staticSprite() {
		return sprite;
	}
	
	
	public int[][] pixels() {
		return sprite.pixels();
	}

	
	@Override
	public int compareTo(Tile other) {
		return this.name().compareTo(other.name());
	}
	


	public static void tickTiles() {
		for(Tile tile : tiles) {
			if (tile instanceof Tickable) {
				((Tickable)tile).tick();
			}
		}
	}
	
	
	public static void addTile(Tile tile) {
		tiles.add(tile);
	}
	
}
